package com.yuhuihui.common.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 异常工具类
 *
 * @author yuhh
 * @date 2023-05-25 14:10:59
 */
public final class ExceptionUtil {

    /**
     * 获取异常堆栈信息
     *
     * @param throwable 异常
     * @return {@link String } 异常堆栈信息
     * @author yuhh
     * @date 2023-05-25 14:11:05
     */
    public static String getStackTrace(Throwable throwable) {
        StringWriter sw = new StringWriter();
        try (PrintWriter pw = new PrintWriter(sw)) {
            throwable.printStackTrace(pw);
            return sw.toString();
        }
    }

    private ExceptionUtil(){

    }
}
